from selenium.webdriver.chrome.service import Service
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import time
import pytest


# 配置 Chrome 选项
chrome_options = Options()
# chrome_options.add_argument("--headless")  # 无头模式
chrome_options.add_argument("--disable-gpu")  # 禁用GPU加速（旧版Chrome可能需要）
chrome_options.add_argument("--no-sandbox")  # Linux环境下需要
chrome_options.add_argument("--window-size=1920,1080")  # 设置窗口大小代替maximize_window()

# 配置Service
service = Service(
    executable_path=r'D:\pulg\webdriver\chromedriver-win64\chromedriver.exe',
    service_args=['--disable-build-check']  # 可选：禁用版本检查
)

# 初始化浏览器
# driver = webdriver.Chrome(service=service, options=chrome_options)  #无头模式
# driver = webdriver.Chrome(service=service)
driver = webdriver.Remote(
    command_executor='http://localhost:4444/wd/hub',
    options=chrome_options,  # 使用 options 代替 desired_capabilities
)
driver.get('https://www.baidu.com')
time.sleep(5)
driver.maximize_window()    #无头模式必须关闭全屏
driver.quit()
